<template>
  <div id="editperson">
      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
        <el-form-item label="姓名" prop="Name">
          <el-input v-model="editForm.Name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="IDNumber">
          <el-input v-model="editForm.IDNumber" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="单位名称" prop="UnitName">
          <el-input v-model="editForm.UnitName" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="colsedialog">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
  </div>
</template>

<script>
export default {
  props: {
    Id: 0
  },
  data () {
    return {
      editLoading: false,
      editFormRules: {
        Name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        IDNumber: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        UnitName: [
          { required: true, message: '请输入单位名称', trigger: 'blur' }
        ]
      },
      // 编辑界面数据
      editForm: {
        Name: '',
        IDNumber: '',
        UnitName: '',
        Id: 0
      }
    }
  },
  mounted () {
    console.log('子页面Id:' + this.Id)
    this.showsubEdit()
  },
  watch: {
    'Id' (to, from) {
      console.log('子页面Id:' + this.Id)
      this.showsubEdit()
    }
  },
  methods: {
    colsedialog () {
      this.$emit('editclosed')
    },
    showsubEdit () {
      let para = {
        id: this.Id
      }
      var _this = this
      _this.editLoading = true
      this.$http
        .post(`/person/details`, para)
        .then(function (response) {
          _this.editLoading = false
          if (response.data.IsSuccess === true) {
            console.log('获取成功')
            _this.editForm = response.data.Result
            console.log('获取姓名测试:' + _this.editForm.Name)
          } else {
            console.log('获取失败:' + response.data.Msg)
            _this.$message({
              message: '获取失败:' + response.data.Msg,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          console.log(error)
          _this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    }
  }
}
</script>
